package com.cgutech.netty.server;

import java.util.Scanner;

public class Application {

    public static void main(String[] args) {
        NettyServer server = new NettyServer(Integer.parseInt(args[0]));
        new Thread(()->{
            try {
                server.doWork();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("工作线程退出");
        }).start();

        boolean isExit = false;
        do {
            Scanner scanner = new Scanner(System.in);
            String cmd = scanner.nextLine();
            switch (cmd) {
                case "quit":
                case "exit":
                    server.close();
                    isExit = true;
                    break;
                case "send":
                    server.broadCast("Hello, I am Server!".getBytes());
                    break;
            }
        } while (!isExit);

        System.out.println("退出");
    }
}
